package Day05;
import java.util.Random;
import java.util.Arrays;
public class MaxArray {

	public static void main(String[] args) {
		//随机生成一个有10个成员的数组
		int[] arr = new int[10];
		int max;
		int min;
		Random ran = new Random();
		for(int i = 0; i < 10; i++) {
			int ranNum = ran.nextInt(100);
			arr[i] = ranNum;
		}
		//找出最大值，并将最大值放扩容后的数组最后面
		max = arr[0];
		for(int i = 1; i < arr.length;i++) {
			if(max < arr[i]) {
				max = arr[i];
			}
		}
		arr = Arrays.copyOf(arr, arr.length + 1);
		arr[arr.length - 1] = max;
		System.out.println("生成的数组为:" + Arrays.toString(arr));
		
		//找出数组最小值，并将最小值放到扩容的新数组最前面
		min = arr[0];
		for(int i = 1; i < arr.length;i++) {
			if(min > arr[i]) {
				min = arr[i];
			}
		}
		int[] arr1 = new int[11];
		System.arraycopy(arr, 0, arr1, 1, arr.length - 1);
		arr1[0] = min;
		System.out.println("生成的数组为1:" + Arrays.toString(arr1));
	}

}
